//
//  MessageEvaluationTableViewCell.m
//  YunDong55like
//
//  Created by junseek on 15-6-9.
//  Copyright (c) 2015年 五五来客 lj. All rights reserved.
//

#import "MessageEvaluationTableViewCell.h"

#import "NSString+WPAttributedMarkup.h"
#import "WPAttributedStyleAction.h"
#import "WPHotspotLabel.h"

@interface MessageEvaluationTableViewCell (){
    //
    NSIndexPath *tempIndexPath;
    NSDictionary *tempDic;
    
    WPHotspotLabel  *lblContent;
    UIView *BGV;
    
}


@end
@implementation MessageEvaluationTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

{
    if (self= [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self setBackgroundColor:RGBCOLOR(255, 255, 255)];
        
        BGV=[[UIView alloc]initWithFrame:CGRectMake(60, 0, kScreenWidth-70, 20)];
        [BGV setBackgroundColor:rgbGray];
        [self addSubview: BGV];
        
        lblContent=[[WPHotspotLabel alloc]initWithFrame:CGRectMake(5, 0, W(BGV)-10, 20)];
        lblContent.textColor=rgbTxtDeepGray;
        lblContent.font=fontSmallTitle;
        lblContent.numberOfLines=0;
        [BGV addSubview:lblContent];
    }
    return self;
}

//内容更新
-(NSInteger )setValueForDictionary:(NSDictionary *)dic indexPath:(NSIndexPath *)indexPath EvaluationCount:(NSInteger)count{
    tempDic=dic;//
    tempIndexPath=indexPath;    
    NSDictionary* style3 = @{@"help":[WPAttributedStyleAction styledActionWithAction:^{
                                if ([self.delegate respondsToSelector:@selector(selectOneUser:object:index:)]) {
                                    [self.delegate selectOneUser:self object:tempDic index:tempIndexPath];
                                }
                            }],
                             @"settings":[WPAttributedStyleAction styledActionWithAction:^{
                                 if ([self.delegate respondsToSelector:@selector(selectTwoUser:object:index:)]) {
                                     [self.delegate selectTwoUser:self object:tempDic index:tempIndexPath];
                                 }
                             }],
                             @"link": rgbBlue,
                             @"content":[WPAttributedStyleAction styledActionWithAction:^{
                                 if ([self.delegate respondsToSelector:@selector(selectContent:object:index:)]) {
                                     [self.delegate selectContent:self object:tempDic index:tempIndexPath];
                                 }
                             }],
                             @"contentColor": rgbTitleColor,
                             
                             };
    

    
    // 是否为第一条评论//![[dic valueForJSONStrKey:@"ruid"] notEmptyOrNull] ||
    if ([[dic valueForJSONStrKey:@"isone"] isEqualToString:@"1"]) {
        NSString *strC= [NSString stringWithFormat:@"<help>%@</help>：<contentColor><content>%@</content></contentColor>",[tempDic valueForJSONStrKey:@"realnamea"],[tempDic valueForJSONStrKey:@"content"]];
        lblContent.attributedText = [strC attributedStringWithStyleBook:style3];
        
    }else{
        NSString *strC= [NSString stringWithFormat:@"<help>%@</help> 回复 <settings>%@</settings>：<contentColor><content>%@</content></contentColor>",[tempDic valueForJSONStrKey:@"realnamea"],[tempDic valueForJSONStrKey:@"realnameb"],[tempDic valueForJSONStrKey:@"content"]];
        lblContent.attributedText = [strC attributedStringWithStyleBook:style3];
        
    }
    
    float flblH=[lblContent sizeThatFits:CGSizeMake( W(lblContent), MAXFLOAT)].height;
    lblContent.frameHeight=flblH+6;
    if (indexPath.row==1) {
        //第一条
        lblContent.frameY=5;
    }else{
        lblContent.frameY=0;
    }
    NSInteger fth=YH(lblContent);
    BGV.frameHeight=fth;
    if (indexPath.row==count) {
        fth+=5;
        BGV.frameHeight=fth;
        fth+=10;
    }
    
    return fth;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
